package com.itheima.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.mapper.PerformanceMapper;
import com.itheima.pojo.Performance;
import com.itheima.pojo.Result;
import com.itheima.pojo.Salary;
import com.itheima.service.PerformanceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class PerformanceServiceImpl extends ServiceImpl<PerformanceMapper, Performance> implements PerformanceService {
    @Autowired
    private PerformanceMapper performanceMapper;

    @Override
//    Result<Page> selectPage(Page page, String keyWord);
    public Result<Page> selectPage(Page page, String employeeName,Integer employeeId,String period,String level) {
        // 创建LambdaQueryWrapper来构造查询条件
        LambdaQueryWrapper<Performance> performanceLambdaQueryWrapper = new LambdaQueryWrapper<>();

        // 进行模糊查询，查询条件是员工姓名
        if (StringUtils.isNotBlank(employeeName)) {
            performanceLambdaQueryWrapper.like(Performance::getEmployeeName, employeeName);
        }
        // 查询条件是绩效周期
        if (StringUtils.isNotBlank(period)) {
            performanceLambdaQueryWrapper.eq(Performance::getEvaluationPeriod, period);
        }

        // 查询条件是绩效等级
        if (StringUtils.isNotBlank(level)) {
            performanceLambdaQueryWrapper.eq(Performance::getLevel, level);
        }
        // 根据Id进行查询（假设Id为员工的唯一标识符）
        if (employeeId != null) {
            performanceLambdaQueryWrapper.eq(Performance::getEmployeeId, employeeId);
        }
        // 调用Mapper的selectPage方法进行分页查询
        Page page1 = performanceMapper.selectPage(page, performanceLambdaQueryWrapper);
        return Result.success(page1);
    }

}
